import java.util.*;

/**
 * @author gao
 * @date 2025/9/2 14:18
 */

public class Solution {
    public List<List<String>> groupAnagrams(String[] strs) {
        Map<String, List<String>> hash = new HashMap<>();

        for (String s : strs) {
            char[] tmp = s.toCharArray();
            // 对字符数组进行排序，这样字母异位词就会变成相同的字符串
            Arrays.sort(tmp);
            String key = new String(tmp);

            if (!hash.containsKey(key)) {
                // 将字符串添加到对应分组
                hash.put(key, new ArrayList<>());
            }
            hash.get(key).add(s);
        }
        return new ArrayList<>(hash.values());
    }

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        while (in.hasNext()) {
            int n = in.nextInt();
            in.nextLine();
            String[] strs = new String[n];
            for (int i = 0; i < strs.length; i++) {
                strs[i] = in.nextLine();
            }
            Solution solution = new Solution();
            System.out.println(solution.groupAnagrams(strs));
        }
    }
}